<!DOCTYPE html PUBLIC "-//W3C//Dtd XHTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/Dtd/xhtml1-transitional.dtd">
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="x-ua-compatible" content="IE=edge, chrome=1">
    <title>j5shop商城</title>
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <link href="/street/css/public.css" type="text/css" rel="stylesheet"/>
    <link href="/street/css/gouwuche.css" type="text/css" rel="stylesheet"/>
    <script type="text/javascript" src="/street/js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="/street/js/slide.js"></script>
    <script src="/js/plugins/layer/layer.min.js"></script>
</head>
<script>
    $(function(){
        $('.nav ul li').hover(function(){
            $(this).children(".details").show();
        },function(){
            $(this).children(".details").hide();
        });
        $('#my').hover(function(){
            $(this).find("div").show();
        },function(){
            $(this).find("div").hide();
        });
    });
</script>
<body>
<div th:replace="street/layout/mallHeader"></div>

<!--------------------内容----------------------->
<div class="wt1080">
    <!--------------标题----------->
    <div class="my_car">
        <h1>我的购物车</h1>
        <div class="place">
            <ul>
                <li class="current"><span>1</span><p>我的购物车</p></li>
                <li><span>2</span><p>提交订单</p></li>
                <li><span>3</span><p>选择支付方式</p></li>
            </ul>
            <span class="heng"></span>
        </div>
    </div>
    <!--------------选择----------->
    <div class="details">
        <div class="title">
            <div style="text-align: left;width: 84px;"><img src="/street/image/k1.png" style="float: left;margin-top: 1px;margin-right: 5px;cursor: pointer"></div>
            <div style="width: 432px;">商品</div>
            <div style="width: 141px;">单价</div>
            <div style="width: 141px;">数量</div>
            <div style="width: 141px;">合计</div>
            <div style="width: 141px;">操作</div>
        </div>
        <!-----------------------商品展示---------------------------->
        <div class="goods">
            <script>
                $(function(){
                    $(".g_one a").toggle(function () {
                                $(this).children('img').attr('src','/street/image/k1.png');
                            },function () {
                                $(this).children('img').attr('src','/street/image/k2.png');
                            }
                    );
                });

            </script>
            <div class="goods_details" th:each="goods:${cartList}">
                <div class="g_one"><a th:href="@{'/street/goodsDetail/'+${goods.goodsid}}"><img src="/street/image/k2.png"></a></div>
                <div class="g_two">
                    <div class="h">
                        <div class="pic"><a th:href="@{'/street/goodsDetail/'+${goods.goodsid}}">
                            <img th:src="@{${goods.img}}"></a></div>
                        <div class="miaoshu">
                            <p style="margin-top: 5px;"><a th:href="@{'/street/goodsDetail/'+${goods.goodsid}}" th:text="${goods.goodsname}">ChildLifH</a></p>
                            <p style="color: #888888;margin-top: 5px;"></p>
                        </div>
                    </div>
                </div>
                <div class="g_three"><p class="y" th:id="'price'+${goods.id}" th:text="${goods.price}">￥198.00</p>
                    <p class="k" th:text="'￥'+${goods.price}">￥118.00</p></div>
                <div class="g_four">
                    <div>
                        <span style="border-right: 1px solid #eeeeee" th:label="${goods.id}"  th:id="'count_down_'+${goods.id}">-</span>
                        <input name="count" th:id="'goods_count_'+${goods.id}" type="text" th:value="${goods.count}">
                        <span style="border-left: 1px solid #eeeeee" th:label="${goods.id}" th:id="'count_up_'+${goods.id}">+</span>
                    </div>
                </div>
                <div class="g_five"><p th:id="'goods_total_price_'+${goods.id}" th:text="'￥'+${goods.totalprice}">￥118.00</p></div>
                <div class="g_six"><span th:onclick="'deleteCart('+${goods.id}+')'"></span></div>
            </div>


        </div>
        <!------------------下部分------------------>
        <div class="d_d">
            <div class="d_d_l">
              <!--  <a href="javascript:;" id="all"><img src="/street/image/k1.png" style="float: left;margin-top: 22px;margin-right: 5px;">全选</a>-->
                <a href="#" style="margin-left: 10px;"></a>
            </div>

            <div class="d_d_r">
                <p class="o"><span></span><font>总价（不含运费）：<span id="totalprice" th:text="${totalprice}">118.00</span></font></p>
                <p class="t">商品应付总计：￥<span id="priceV" th:text="${totalprice}"></span><font></font></p>
            </div>
            <a href="#" onclick="jiesuan()" class="jiesuan">立即购买</a>
        </div>
    </div>
    <!---------------------热销------------------>
    <div class="hot">
        <div class="title">热销推荐</div>
        <div class="content">
            <ul>
                <li th:each="com:${commList}">
                    <div class="pic"><a th:href="@{'/street/goodsDetail/'+${com.id}}">
                        <img th:src="@{${com.img}}"></a></div>
                    <p class="c_t"><a th:href="@{'/street/goodsDetail/'+${com.id}}" th:text="${com.title}">Regen10片</a></p>
                    <p class="price" th:text="'￥'+${com.prices}">￥89.00</p>
                    <a href="#" class="goumai" th:onclick="'addCart('+${com.id}+')'">立即购买</a>
                </li>
            </ul>
            <div class="clear"></div>
        </div>
    </div>
</div>
<script type="text/javascript">
    function goods_count_adjust(cart_id,count){
        jQuery.post("/person/street/goods_count_adjust",{"cart_id":cart_id,"count":count},function(data){
            if(data.code==0){
                jQuery("#goods_count_"+cart_id).val(count);
                jQuery("#goods_count_"+cart_id).attr("goods_count",count)
                jQuery("#goods_total_price_"+cart_id).html("¥"+data.goodsprice);
                jQuery("#totalprice").html(data.totalprice);
            }
            if(data.code=="200"){
                alert("库存不足，请重新选择数量！");
                jQuery("#goods_count_"+cart_id).val(jQuery("#goods_count_"+cart_id).attr("goods_count"));
            }
            if(data.code=="300"){
                alert("团购库存不足，请重新选择数量！");
                jQuery("#goods_count_"+cart_id).val(jQuery("#goods_count_"+cart_id).attr("goods_count"));
            }
        },"json");
    }
    jQuery("span[id^=count_down]").click(function(){
        var cart_id=jQuery(this).attr("label");
        var count=jQuery("#goods_count_"+cart_id).val();
        if(count>1){
            count--;
            goods_count_adjust(cart_id,count)
        }
    });
    jQuery("span[id^=count_up]").click(function(){
        var cart_id=jQuery(this).attr("label");
        console.log('cart_id:'+cart_id);
        var count=jQuery("#goods_count_"+cart_id).val();
        if(count>0){
            count++;
            goods_count_adjust(cart_id,count);
        }
    });

    function addCart(goodsid){
        console.log(goodsid);
        var count=1;
        $.ajax({
            type: "post",
            url: '/person/street/addCart',
            data: {
                goodsid:goodsid,
                count:count},
            dataType: "json",
            success:function(data) {
                if(data.code==0){
                    window.location.href = "/person/street/likBuy/"+goodsid;
                }else if(data.success=='login'){
                    window.location.href = "/street/login"
                }
            }
        });
    }
    function deleteCart(goodsid){
        $.ajax({
            type: "post",
            url: '/person/street/deleteCart',
            data: {
                goodsid:goodsid
            },
            dataType: "json",
            success:function(data) {
                if(data.code==0){
                    layer.msg("删除购物车成功!");
                }else if(data.success=='login'){
                    window.location.href = "/street/login"
                }
            }
        });
    }
    function jiesuan(){
        window.location.href = "/person/street/likBuy1";
    }
    function addRePly(){
        var content=$("#say_some").val();
        var goodsid=$("#goodsid").val();
        $.ajax({
            type: "post",
            url: '/person/street/addRePly',
            data: {content:content,goodsid:goodsid},
            dataType: "json",
            success:function(data) {
                if(data.success){
                    layer.msg("评论成功!",{icon:2});

                }else{
                    layer.msg("评论失败!",{icon:2});
                }
            }
        });
    }
</script>

<div th:replace="street/layout/mallFooter"></div>
</body>
</html>
